package helperService

import (
	"gitee.com/yangguoliang001/go-gin-vue3/QO"
	"gitee.com/yangguoliang001/go-gin-vue3/dao/helperDao"
	"gitee.com/yangguoliang001/go-gin-vue3/vo"
	"github.com/gin-gonic/gin"
	"github.com/go-redis/redis/v7"
	"go.uber.org/zap"
	"gorm.io/gorm"
)

type HelperService interface {
	SearchCache(c *gin.Context, cacheReq QO.CacheReq) (searchRes vo.SearchCacheVO, err error)
	ClearCache(c *gin.Context, cacheReq QO.CacheReq) (clearRes vo.ClearCacheVO, err error)
	QueryDbs(c *gin.Context) (dbsRes vo.DbsVO, err error)
	QueryTables(c *gin.Context, tableReq QO.DbTableReq) (tableRes vo.DbTableVO, err error)
	SearchMysql(c *gin.Context, searchReq QO.SearchMysqlReq) (searchRes vo.SearchMysqlDataVO, err error)
}

type helperService struct {
	logger    *zap.Logger
	cache     *redis.Client
	helperDao helperDao.HelperDao
}

func New(db *gorm.DB, cache *redis.Client, logger *zap.Logger) HelperService {
	return &helperService{
		logger:    logger,
		cache:     cache,
		helperDao: helperDao.New(db),
	}
}
